vim.g.mapleader = " "

local keymap = vim.keymap

-- ---------- 插入模式 ---------- ---
keymap.set("i", "jk", "<ESC>")

-- ---------- 视觉模式 ---------- ---
-- 单行或多行移动
keymap.set("v", "J", ":m '>+1<CR>gv=gv")
keymap.set("v", "K", ":m '<-2<CR>gv=gv")

-- 向右移动选中的行
keymap.set("v", "H", "<gv") -- 向右缩进
-- 向左移动选中的行
keymap.set("v", "L", ">gv") -- 向左缩进

-- ---------- 正常模式 ---------- ---
-- 窗口
keymap.set("n", "<leader>sv", "<C-w>v") -- 水平新增窗口
keymap.set("n", "<leader>sh", "<C-w>s") -- 垂直新增窗口

-- 取消高亮
keymap.set("n", "<leader>nh", ":nohl<CR>")

-- 切换buffer
keymap.set("n", "<S-L>", ":bnext<CR>")
keymap.set("n", "<S-H>", ":bprevious<CR>")
keymap.set("n", "<leader>x", ":bdelete<CR>")
-- ---------- 插件 ---------- ---
-- nvim-tree
keymap.set("n", "<leader>-", ":NvimTreeToggle<CR>")

-- ---------- 上下文跳转 ---------- ---
keymap.set("n", "<Leader>l", function()
	require("treesitter-context").go_to_context(vim.v.count1)
end, { silent = true })

-- ---------- toggleterm.nvim 终端切换 ---------- ---
-- 切换到终端 1
-- 通过 Alt + p + 1 切换到终端 1
keymap.set("n", "<leader>t1", ":ToggleTerm 1<CR>", { noremap = true, silent = true })
keymap.set("n", "<leader>t2", ":ToggleTerm 2<CR>", { noremap = true, silent = true })
keymap.set("n", "<leader>t3", ":ToggleTerm 3<CR>", { noremap = true, silent = true })
keymap.set("n", "<leader>t4", ":ToggleTerm 4<CR>", { noremap = true, silent = true })

vim.api.nvim_set_keymap('i', '<C-s>', 'copilot#Accept()', { expr = true, noremap = true, silent = true })
